package com.lanou3g.musicenjoy.activities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.lanou3g.musicenjoy.R;
import com.umeng.socialize.utils.Log;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by 李宁 on 15/11/2.
 * 欢迎页
 */
public class WelcomeActivity extends Activity{
    private final int SPLASH_DISPLAY_LENGHT = 2000;
    private SharedPreferences preferences;
    private SharedPreferences.Editor editor;
    private ImageView splash_img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        Log.i("aaaa", "sss");
        splash_img = (ImageView) findViewById(R.id.splash_img);
        preferences = getSharedPreferences("phone", Context.MODE_PRIVATE);
        AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);
        animation.setDuration(2000);
        splash_img.startAnimation(animation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (preferences.getBoolean("firststart", true)){
                            editor = preferences.edit();
                            //将登陆标识位置为false, 下次登陆时不再显示引导界面
                            editor.putBoolean("firststart", false);
                            editor.commit();
                            Intent intent = new Intent(WelcomeActivity.this, AndyViewPagerActivity.class);
                            WelcomeActivity.this.startActivity(intent);
                            WelcomeActivity.this.finish();
                        } else {
                            Intent intent = new Intent(WelcomeActivity.this, HelloDrawerActivity.class);
                            WelcomeActivity.this.startActivity(intent);
                            WelcomeActivity.this.finish();
                        }
                    }
                }, SPLASH_DISPLAY_LENGHT);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

    }
    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }

}
